package com.blast.cn.persenter.splash

import android.Manifest
import android.annotation.SuppressLint
import com.lxj.xpopup.util.XPermission
import com.tbruyelle.rxpermissions2.RxPermissions
import com.wxl.common.base.WorkPresenter
import com.wxl.common.util.Toll
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers

class ApplyPermissionPresenter : WorkPresenter() {


    @SuppressLint("CheckResult")
    override fun onStartDoWork(vararg rgs: Any) {
        RxPermissions.getInstance(rootView.context)
            .request( Manifest.permission.ACCESS_COARSE_LOCATION,
                Manifest.permission.ACCESS_FINE_LOCATION,
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.CALL_PHONE,
                Manifest.permission.CAMERA,
                Manifest.permission.ACCESS_WIFI_STATE,
                Manifest.permission.ACCESS_NETWORK_STATE,
                "ccom.zhentianxia.cn.permission.RECEIVE_MSG",
                "com.zhentianxia.cn.permission.RECEIVE_MSG",
                "com.zhentianxia.cn.permission.INCOMING_CALL",
                "android.permission.RECORD_AUDIO")
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(Consumer{
                if(it){
                    doNext()
                } else {
                    Toll.toll("未获得相关权限，请到设置中打开权限")
                    XPermission.create(rootView.context)
                        .launchAppDetailsSettings()
                }
            })
    }
}